<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>

<%@ page import="com.dog.lucene.first.IndexSearch" %>
<%@ page import="com.dog.lucene.first.IndexManager" %>
<%@ page import="com.dog.domain.Crawl" %>
<%@ page import="java.util.List" %>
<%@ page import="org.wltea.analyzer.lucene.IKAnalyzer" %>
<%@ page import="org.apache.lucene.analysis.standard.StandardAnalyzer" %>
<%@ page import="org.apache.lucene.index.IndexReader" %>
<%@ page import="org.apache.lucene.queryparser.classic.QueryParser" %>
<%@ page import="org.apache.lucene.search.IndexSearcher" %>
<%@ page import="org.apache.lucene.search.Query" %>
<%@ page import="java.util.ArrayList" %>


<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Insert title here</title>
<script src="http://cdn.static.runoob.com/libs/jquery/1.10.2/jquery.min.js"></script>
	<style type="text/css">
	</style>
</head>
<body>


	
<form action="query.jsp" method="GET">
站点名: <input type="text" name="name">
<br />
<input type="submit" value="提交" />

</form>
<%

List <Crawl> lis=new ArrayList();


//IndexManager b=new IndexManager();
//b.createIndex();
//out.print("索引成功");


//mmp俩个分开，免得又注释了
//解决中文乱码


String test = null; 
 
try {
	String str = new String(request.getParameter("name").getBytes("ISO-8859-1"),"utf-8");
	//就是不知道为什么str不赋值给test的话会一直报错？？？这个好好的去研究一下
	//out.print(str);
	test=str;
	IndexSearch a=new IndexSearch();
	QueryParser parser = new QueryParser("description",
			new IKAnalyzer());
	Query query = parser.parse(str);
	lis=a.doSearch(query);
	if(lis.size()==0){
		out.print("没有查询到结果");
	}
	else{	
		
	}

} catch (Exception e) {
	// TODO Auto-generated catch block
	e.printStackTrace();
}


int i=0;
for(Crawl crawl: lis){
	i=i+1;
	//out.print(crawl.getDescription()+"<br>"+"<br>");
}

%>

<script type="text/javascript">


$(function(){
    var Count = "<%=i %>";//记录条数
    var tmp = "<%=test %>";
    var PageSize=5;//设置每页示数目
    var PageCount=Math.ceil(Count/PageSize);//计算总页数
    var currentPage =1;//当前页，默认为1。
    //造个简单的分页按钮
    for(var i=1;i<=PageCount;i++){
	if(PageCount==1){
		
	}
	else{
		
	var pageN='<a href="?name='+tmp+'&a='+i+'">第'+i+'页</a>'+' '; //意思的话就是左右俩边都是用加号来进行的？看起来又意思呢
	$('#page').append(pageN);
		
	
	}
    }
    
	//显示默认页（第一页）

});  
</script>








<%

String d =request.getParameter("a");    //分页数的话改的要比较多一点哦
//out.print(d+"<br>");
int b=0;
int k=0;
if(i!=0&&d==null){
	for(Crawl crawl: lis){
		if(5>k&&k>=0){
			out.print("<a href=\""+crawl.getUrl()+"\">"+crawl.getAbs()+"</a>"+"<br>"); 
			out.print(crawl.getDescription()+"<br>");   //如果选择分页的话，这个数据会改很多
		}
		k=k+1;
	}
	
	
}
else{
if(d!=null){
int c=Integer.valueOf(d);
//out.print(c);
for(Crawl crawl: lis){
	if(c*5>b&&b>=(c-1)*5){
		if(crawl.getDescription()==null){
			out.print("");
		}
		else{
			out.print("<a href=\""+crawl.getUrl()+"\">"+crawl.getAbs()+"</a>"+"<br>"); 
		
		out.print(crawl.getDescription()+"<br>");
		}
	}
	b=b+1;	
}
}
}

//原来在这边的话就是要传入俩个参数，第一个的话name=防盗网&&a=

%>


<br/>
	<div id="page" style="width:450px;margin:0 auto;"></div>

</body>
</html>
